# 爬取斗破苍穹小说
# https://doupocangqiong1.com/1/1.html
# .....
# https://doupocangqiong1.com/1/1692.html

import requests
import re
import time

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"}
f = open("C:\\Users\\Administrator\\Desktop/dpcq.txt", 'a+')  # 新建txt文档，追加的方式


def get_info(url):
    res = requests.get(url, headers=headers)
    if res.status_code == 200:
        contents = re.findall('<div class="content" id="chaptercontent">(.*?)</div>', res.text, re.S)
        for content in contents:
            f.write(content)
    else:
        pass


if __name__ == '__main__':
    urls = ['https://doupocangqiong1.com/1/{}.html'.format(str(i)) for i in range(1, 3)]

    for url in urls:
        get_info(url)
        time.sleep(1)
f.close()
